//
//  DBManager.m
//  DuBai
//
//  Created by darktm on 14-3-17.
//  Copyright (c) 2014年 darktm. All rights reserved.
//

#import "DBManager.h"

static DBManager *_dbManager = nil;

@interface DBManager ()
{
    WYDatabase *_db;
}
@end

@implementation DBManager

@synthesize db = _db;

+(instancetype)shareInstance:(DBType)type{
    
    if(!_dbManager){
        _dbManager = [[self alloc] initWithType:type];
    }
    return _dbManager;
}

-(instancetype)initWithType:(DBType)type{
    self = [super init];
    
    if(self){
        
        NSString *path = nil;
        if(type == DBTypeCn){
        
            path =   [[NSString getFolderWithType:NSCachesDirectory] stringByAppendingPathComponent:@"db_cn.sqlite"];
            
        }else if(type == DBTypeEn){
            
            path =   [[NSString getFolderWithType:NSCachesDirectory] stringByAppendingPathComponent:@"db_en.sqlite"];
        }
        _db = [WYDatabase openDatabaseWitPath:path];
    }
    
    return self;
}

-(void)reset{
    
    [self.db close];
    _dbManager = nil;
}
@end
